package com.global.college.ui.presenter;

import android.content.Context;

import com.global.college.api.ProgressSubscriber;
import com.global.college.base.BasePresenter;
import com.global.college.ui.bean.MyOrderDetail;
import com.global.college.ui.bean.MyOrderListModel;
import com.global.college.ui.interfaces.IOrderView;

/**
 * 订单
 */
public class OrderPresenter extends BasePresenter {

    private IOrderView mIOrderView;

    public OrderPresenter(Context context) {
        super(context);
    }

    public void setOrderView(IOrderView orderView){
        mIOrderView = orderView;
    }

    /**
     * 订单列表
     * @param
     */
    public void getOrderList(String userId, String orderState, int pageNum, int pageSize){
        mRequestClient.getOrderList( userId,  orderState,  pageNum,  pageSize).subscribe(new ProgressSubscriber<MyOrderListModel>(mContext,true) {
            @Override
            public void onNext(MyOrderListModel object) {
                if(null != mIOrderView){
                    mIOrderView.onGetOrderListSuccess(object);
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIOrderView){
                    mIOrderView.onGetOrderListFail(e.getMessage());
                }
            }
        });
    }

    /**
     * 订单详情
     * @param
     */
    public void getOrderDetail(String orderId){
        mRequestClient.getOrderDetail(orderId).subscribe(new ProgressSubscriber<MyOrderDetail>(mContext,true) {
            @Override
            public void onNext(MyOrderDetail smsModel) {
                if(null != mIOrderView){
                    mIOrderView.onGetOrderDetailSuccess(smsModel);
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIOrderView){
                    mIOrderView.onGetOrderDetailFail(e.getMessage());
                }
            }
        });
    }


    /**
     * 创建订单
     * @param
     */
    public void createOrder(String userId, String goodId){
        mRequestClient.createOrder( userId,  goodId).subscribe(new ProgressSubscriber<Object>(mContext,true) {
            @Override
            public void onNext(Object object) {
                if(null != mIOrderView){
                    mIOrderView.onCreateOrderSuccess(object);
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIOrderView){
                    mIOrderView.onCreateOrderFail(e.getMessage());
                }
            }
        });
    }

    /**
     * 取消订单
     * @param
     */
    public void cancleOrder(String orderId){
        mRequestClient.cancleOrder(orderId).subscribe(new ProgressSubscriber<Object>(mContext,true) {
            @Override
            public void onNext(Object object) {
                if(null != mIOrderView){
                    mIOrderView.onCancleOrderSuccess(object);
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIOrderView){
                    mIOrderView.onCancleOrderFail(e.getMessage());
                }
            }
        });
    }

}
